<?php 
	include ("../../Connections/SCMS.php");
   include ("../../Model/CheckClass.php");
   include ("../../Model/errorReportClass.php");
   include ("../../Model/databaseOperationClass.php");
   $Check = new CheckClass();
   $errReport = new errorReportClass();
   $databaseOperation = new databaseOperationClass();
	
   $sid = $_GET['id'];
   $name = $_POST['name'];
   $number = $_POST['number'];
   $cost = $_POST['cost'];
   $property = $_POST['property'];
   $stockno = $_POST['stockno'];
	
 	//Set report pass.
	$reportTo = '../view/StockViewChange.php';	
	$reportSuccese = '../view/StockViewList.php';	
	//Check value null.
   if($Check->IsNull($name)){  // If null Report error.
       $errReport->errorReport(3, $reportTo);
       exit;
   }
   else if($Check->IsNull($number)){
       $errReport->errorReport(4, $reportTo);
       exit;
   }
   else if($Check->IsNull($cost)){
       $errReport->errorReport(5, $reportTo);
       exit;
   }
   else if($Check->IsNull($property)){
       $errReport->errorReport(6, $reportTo);
       exit;
   }
   else if($Check->IsNull($stockno)){
       $errReport->errorReport(7, $reportTo);
       exit;
   }
   else if($Check->IsNull($sid)){
       $errReport->errorReport(12, $reportTo);
       exit;
   }
   //Check value number.
  /*else if($Check->notNumber($stockno)){
       $errReport->errorReport(8, $reportTo);
       exit;
   }
   else if($Check->notNumber($number)){
       $errReport->errorReport(9, $reportTo);
       exit;
   }
   else if($Check->notCost($cost)){
       $errReport->errorReport(10, $reportTo);
       exit;
   }
   //Check value is String
   else if($Check->notString($name)){
       $errReport->errorReport(11, $reportTo);
       exit;
   }*/
	
	$delete = $databaseOperation->deleteFromStock($sid);
	if(!$delete){
      $errReport->errorReport(13, $reportTo);
		exit;
   }
		
	$success = $databaseOperation->insertIntoStock($sid, $name, $number, $cost, $property, $stockno);
	if($success){
      $errReport->errorReport(1, $reportSuccese);
      exit;
   }
   else{
       $errReport->errorReport(2, $reportTo);
       exit;
   }	
?>